package com.zjeav.lingjiao.ui.home.persenter;

import android.support.annotation.NonNull;

import com.zjeav.lingjiao.base.baseBean.Result;
import com.zjeav.lingjiao.base.request.BookRequest;
import com.zjeav.lingjiao.base.response.BooksResponse;
import com.zjeav.lingjiao.ui.home.model.HomeModel;
import com.zjeav.lingjiao.ui.home.view.GetBookContract;

public class GetbookPersenter implements GetBookContract.Presenter,HomeModel.OnMainListener {

    private HomeModel module;
    private GetBookContract.View view;

    public GetbookPersenter(GetBookContract.View view) {
        this.view = view;
        this.module = new HomeModel();
    }


    @Override
    public void OnMyBooksSuccess(Result<BooksResponse> result) {
        this.view.showBookSuccess(result.getData());
    }

    @Override
    public void OnError(Throwable throwable) {
        this.view.showBookFailure(throwable);
    }

    @Override
    public void getbook(BookRequest request) {
        this.module.getMyBooks(request,this);
    }

    @Override
    public void attachView(@NonNull GetBookContract.View view) {
        this.view = view;
    }

    @Override
    public void detachView() {
        this.view = null;
    }
}
